package com.shuziren.config;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.shuziren.Intervie.InterviewQuestion;

import java.io.IOException;

public class DifficultyDeserializer extends JsonDeserializer<InterviewQuestion.Difficulty> {
    @Override
    public InterviewQuestion.Difficulty deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        String value = p.getText();
        if (value == null || value.isEmpty()) {
            return null; // 或者设置默认值，例如 InterviewQuestion.Difficulty.EASY
        }
        try {
            return InterviewQuestion.Difficulty.valueOf(value.toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new IOException("Invalid difficulty value: " + value, e);
        }
    }
}